#ifndef _SOCK_MSG_H
#define _SOCK_MSG_H

extern int cliFd;

int initSockClient(void);

void * sockRecvFunc(void * paramIn);

int sendSockMsgToAct(void * msgHead, const void * paramIn);

int encodeInt(int dataIn,char * buff);

//int encodeMsgHead(void * pstMsgHead, char * buff);
int encodeMsgHead(void * pstMsgHeadIn, char * buff, int moduleConverted = 0);

#define HASH_SIZE_SOCK_ACT_CTL 20

typedef struct _sock_act_ctl
{
    int actId;
    int status;
    int expectDataType;
    union
    {
        int data_i;
        float data_f;
    }un_data;

}sock_act_ctl;

typedef struct _act_ctl_node
{
    int actId;
    int status;
    struct _sock_act_ctl * ptrBack;
    struct _act_ctl_node * next;
}act_ctl_node;

void initCtlTable(void);
void clearCtlTable(void);

void init_msg_buff_list(void);
void clear_msg_buff_list(void);

int calcActId(int moduleTypeIn,int actTypeIn,int component);

int checkActReady(int actId);

act_ctl_node * setExpectData(sock_act_ctl * pstCtlDataIn);
void sendToActAndWaitResp(void * msgHead, const void * paramIn,
int timeMs,act_ctl_node * nodeToCheck,
void * respOut);

void procReportMsg(int dataLen, char * dataIn);
int initSockServer(int needCreateThread);

typedef struct _switch_ctl
{
    unsigned char chanNum;
    unsigned char isClose;
    int duration;//ms
}switch_ctl;

typedef struct _heat_ctl
{
    unsigned char chanNum;
    unsigned char isClose;
    float temperature;
}heat_ctl;

typedef struct _qpcr_move
{
    int motorType;
    int pos;
}qpcr_move;

typedef struct _logistic_move
{
    int submodule;
    int posTypeInner;
}logistic_move;

#endif